package sword_offer;

/**
 * @author Synhard
 * @version 1.0
 * @Class sword_offer.Code25
 * @Description 输入两个递增排序的链表，合并这两个链表并使新链表中的节点仍然是递增排序的。
 * @tel 13001321080
 * @email 823436512@qq.com
 * @date 2021-03-16 11:05
 */
public class Code25 {
    public ListNode mergeTwoLists(ListNode l1, ListNode l2) { // 将l2的结点合并在l1中
        if(l1 == null || l2 == null) {
            return l1 == null ? l2 : l1;
        }

        if(l1.val<l2.val)
        {
            l1.next = mergeTwoLists(l1.next, l2);
            return l1;
        }
        else
        {
            l2.next = mergeTwoLists(l1, l2.next);
            return l2;
        }
    }
}
